package com.jintian.smart.kernel.orm.raw.condition;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonTypeName("LogicQuery")
public class LogicCondition extends RawCondition {
    @JsonProperty("query")
    private RawCondition query;

    @JsonProperty("logic")
    private Logic logic;

    public LogicCondition() {
    }

    public LogicCondition(Logic logic, RawCondition query) {
        this.query = query;
        this.logic = logic;
    }

    @Override
    public String toSql() {
        return logic.op() + " " + query.toSql();
    }

    @Override
    public List<Object> toParamList() {
        List<Object> params = new ArrayList<>();
        params.addAll(query.toParamList());
        return params;
    }
}
